package org.sjs.dreamfly.biz.movie

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import jp.wasabeef.glide.transformations.RoundedCornersTransformation
import org.sjs.dreamfly.R
import org.sjs.dreamfly.model.MovieInfo
import org.sjs.dreamfly.common.util.Router

class MovieListViewHolder(itemView: View, val channelType: String) : RecyclerView.ViewHolder(itemView) {
    fun bind(movieInfo: MovieInfo, position: Int) {
        itemView.findViewById<TextView>(R.id.movie_name).text = movieInfo.name
        itemView.findViewById<TextView>(R.id.movie_subtitle).text = movieInfo.subTitle
        itemView.findViewById<ImageView>(R.id.movie_cover).let {
            Glide.with(itemView.context)
                .load(movieInfo.getLandscapeImage()?:movieInfo.imageUrl)
                .placeholder(R.color.background)
                .transform(
                    RoundedCornersTransformation(46, 0,
                    RoundedCornersTransformation.CornerType.TOP)).into(it)
            it.setOnClickListener {
                Router.launchMovieDetail(movieInfo, channelType)
            }
        }
    }
}